package logic

import (
	"context"
	"house_srv/models"

	"house_srv/home"
	"house_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type HomeCreateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewHomeCreateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HomeCreateLogic {
	return &HomeCreateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *HomeCreateLogic) HomeCreate(in *home.HomeCreateRequest) (*home.HomeCreateResponse, error) {
	var err error
	var h models.Home
	h.Title = in.Title
	h.Address = in.Address
	h.Num = int(in.Num)
	h.Price = float64(in.Price)
	err = h.Create()
	if err != nil {
		logx.Error("发布房源失败", err)
		return nil, err
	}

	return &home.HomeCreateResponse{
		HomeId: int64(h.ID),
	}, nil
}
